package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.Dictionary;
import com.olddriver.crm.mapper.DictionaryMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.QueryObject;
import com.olddriver.crm.service.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DictionaryServiceImpl implements IDictionaryService {
    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Override
    public List<Dictionary> queryMenu() {
        return dictionaryMapper.getMenu();
    }

    @Override
    public PageResult queryWords(QueryObject qo, Long id) {
        int total = dictionaryMapper.totalWord(id);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        } else {
            return new PageResult(total, dictionaryMapper.getWords(id, qo));
        }
    }

    @Override
    public void update(Dictionary dictionary) {
        dictionaryMapper.update(dictionary);
    }

    @Override
    public void insert(Dictionary dictionary) {
        dictionaryMapper.insert(dictionary);
    }

    @Override
    public void deleteWord(Long id) {
        dictionaryMapper.deleteWord(id);
    }

    @Override
    public void deleteMenu(Long id) {
        dictionaryMapper.deleteMenu(id);
    }

    @Override
    public List<Dictionary> getWords(String sn) {
        return dictionaryMapper.getWordsBySn(sn);
    }


}
